﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SolutionGenerator
{
    public class WizardEngine
    {
        private List<UserControlParent> _wizardPages = new List<UserControlParent>();
        private Control _contentWizardPanel;
        private WizardStep currentStep;
        public List<UserControlParent> WizardPages
        {
            get { return _wizardPages; }
        }
        public WizardEngine(Control contentWizardPanel, WizardStep startStep, 
            List<UserControlParent> wizPages)
        {
            _contentWizardPanel = contentWizardPanel;
            currentStep = startStep;
            _wizardPages = wizPages;
            ShowCurrentPages();
        }
        private void ShowCurrentPages()
        {
            _contentWizardPanel.Controls.Clear();
            _contentWizardPanel.Controls.Add(_wizardPages[(int)currentStep]);
            _wizardPages[(int)currentStep].LoadWizard();
        }
        public void PreviousPage()
        {
            int indexStep = (int)currentStep;
            currentStep = (WizardStep)Enum.GetValues(currentStep.GetType()).GetValue(indexStep - 1);
            ShowCurrentPages();
        }
        public void NextPage()
        {
            UserControlParent _currentPages = GetCurrentPages;
            if (_currentPages.IsPageValid)
            {
                _currentPages.Save();
                int indexStep = (int)currentStep;
                currentStep = (WizardStep)Enum.GetValues(currentStep.GetType()).GetValue(indexStep + 1);
                ShowCurrentPages();
            }
            else
                MessageBox.Show(_currentPages.ValidationMessage);
        }
        private UserControlParent GetCurrentPages
        {
            get
            {
                return _wizardPages[(int)currentStep];
            }
        }
        public string WizardTitle
        {
            get
            {
                return GetCurrentPages.WizardTitle;
            }
        }
        public int GetCurrentPage
        {
            get { return (int)currentStep + 1; }
        }
        public int GetTotalPage
        {
            get { return _wizardPages.Count; }
        }
        public bool IsNextAvailable
        {
            get { return GetCurrentPage < GetTotalPage; }
        }
        public bool IsPrevAvailable
        {
            get { return GetCurrentPage > 1; }
        }
    }
}